4 This is a cleaner version of 10897.cpp
10 const long double rho
= 6371.01;//km
11 const long double pi
= 2*acos(0.0);
14 //A geometrical vector
16 long double dot(const Vector
&t
) const{
17 return x
*t
.x
+ y
*t
.y
+ z
*t
.z
;
19 long double mag() const{
20 return sqrt(x
*x
+ y
*y
+ z
*z
);
25 //A point in spherical coordinates
27 long double phi
, theta
;
28 Vector
toVector() const{
30 v
.x
= sin(phi
)*cos(theta
);
31 v
.y
= sin(phi
)*sin(theta
);
37 istream
& operator >> (istream
&in
, point
&p
){
38 long double a
, b
, c
, d
, e
, f
;
40 in
>> a
>> b
>> c
>> X
>> d
>> e
>> f
>> Y
;
42 long double latitude
, longitude
;
43 latitude
= (a
+ b
/60.0 + c
/3600.0);
44 longitude
= (d
+ e
/60.0 + f
/3600.0);
46 p
.phi
= 90 + latitude
* (X
== 'N' ? -1.0 : 1.0);
47 p
.theta
= longitude
* (Y
== 'E' ? -1.0 : 1.0);
49 p
.phi
*= pi
/180.0, p
.theta
*= pi
/180.0; //"radianize"
53 long double dist(point
&a
, point
&b
){
54 //Convert shperical coordinates to rectangular coordinates...
55 Vector va
= a
.toVector(), vb
= b
.toVector();
56 //find angle between the two vectors...
57 long double angle
= acos(va
.dot(vb
) / (va
.mag()*vb
.mag()) );
58 //calculate length of circle arc... (rho is the radius)
64 for (scanf("%d", &n
); n
--; ){
68 cout
<< fixed
<< dist(a
, b
) << endl
;